package com.romadan.core.nonlinearanalys.fet.volterra;

import java.util.ArrayList;
import java.util.List;

import com.romadan.core.linearanalys.fet.model14els.ExtrinsicElements;
import com.romadan.core.linearanalys.fet.model14els.IntrinsicElements;
import com.romadan.core.linearanalys.logic.LParameters;
import com.romadan.core.nonlinearanalys.fet.volterra.logic.EdgeType;
import com.romadan.core.nonlinearanalys.fet.volterra.logic.GraphType;
import com.romadan.core.nonlinearanalys.fet.volterra.logic.NodeType;

public class ConvertFromSchemaToGraph {
	private GraphType graph;
	private LParameters lParameters;
	public ConvertFromSchemaToGraph(LParameters lParameters) {
		this.lParameters = lParameters;
	}
	
	public GraphType convert() {
		int id = getId();
		graph = new GraphType(id);
		ExtrinsicElements extElements = lParameters.getExtElements();
		IntrinsicElements intElements = lParameters.getIntElements();
		
		List<EdgeType> edges = new ArrayList<EdgeType>();
		List<NodeType> nodes = new ArrayList<NodeType>();
		for (int i=0; i<10; i++) {
			NodeType node = new NodeType(i);
			nodes.add(node);
		}
		
		EdgeType edge_Rin = new EdgeType(1, nodes.get(0), nodes.get(1), "R");
		edge_Rin.setValue(50);
		edges.add(edge_Rin);
		
		EdgeType edge_Lg = new EdgeType(2, nodes.get(1), nodes.get(2), "L");
		edge_Lg.setValue(extElements.getLg());
		edges.add(edge_Lg);
		
		EdgeType edge_Cpg = new EdgeType(3, nodes.get(0), nodes.get(2), "C");
		edge_Cpg.setValue(extElements.getCpg());
		edges.add(edge_Cpg);
		
		EdgeType edge_Rg = new EdgeType(4, nodes.get(2), nodes.get(3), "R");
		edge_Rg.setValue(extElements.getRg());
		edges.add(edge_Rg);
		
		EdgeType edge_Cgs = new EdgeType(5, nodes.get(3), nodes.get(4), "C");
		edge_Rg.setValue(intElements.getCgs());
		edges.add(edge_Cgs);
		
		EdgeType edge_Rgs = new EdgeType(6, nodes.get(4), nodes.get(5), "R");
		edge_Rg.setValue(intElements.getRgs());
		edges.add(edge_Rgs);
		
		EdgeType edge_Rs = new EdgeType(7, nodes.get(5), nodes.get(6), "R");
		edge_Rs.setValue(extElements.getRs());
		edges.add(edge_Rs);
		
		EdgeType edge_Ls = new EdgeType(8, nodes.get(6), nodes.get(0), "L");
		edge_Ls.setValue(extElements.getLs());
		edges.add(edge_Ls);
		
		EdgeType edge_Cgd = new EdgeType(9, nodes.get(3), nodes.get(7), "C");
		edge_Cgd.setValue(intElements.getCgd());
		edges.add(edge_Cgd);
		
		EdgeType edge_gm = new EdgeType(10, nodes.get(7), nodes.get(5), "G");
		edge_gm.setValue(intElements.getGm());
		edge_gm.setRun_edge(edge_Cgs);
		edges.add(edge_gm);
		
		EdgeType edge_Gds = new EdgeType(11, nodes.get(7), nodes.get(5), "G");
		edge_Gds.setValue(intElements.getGds());
		edges.add(edge_Gds);
		
		EdgeType edge_Cds = new EdgeType(12, nodes.get(7), nodes.get(5), "C");
		edge_Cds.setValue(intElements.getCds());
		edges.add(edge_Cds);
		
		EdgeType edge_Rd = new EdgeType(13, nodes.get(7), nodes.get(8), "R");
		edge_Rd.setValue(extElements.getRd());
		edges.add(edge_Rd);
		
		EdgeType edge_Cpd = new EdgeType(14, nodes.get(0), nodes.get(8), "C");
		edge_Cpd.setValue(extElements.getCpg());
		edges.add(edge_Cpd);
		
		EdgeType edge_Ld = new EdgeType(15, nodes.get(9), nodes.get(8), "L");
		edge_Ld.setValue(extElements.getLd());
		edges.add(edge_Ld);
		
		EdgeType edge_Rout = new EdgeType(16, nodes.get(0), nodes.get(9), "R");
		edge_Rout.setValue(50);
		edges.add(edge_Rout);
		
		graph.setNodes(nodes);
		graph.setEdges(edges);
		
		return graph;
	}
	
	private static int counter = 0;
	private static int getId() {
		return counter++;
	}
}
